package com.ielts.model;

import vn.com.baseapplication.util.HexStringConverter;
import vn.com.hoasua.database.adbException;
import vn.com.hoasua.database.adbObject;

import com.ielts.activity.R;

@SuppressWarnings("serial")
public class ItemTopics extends adbObject {
	public static final String CLASS_UNIQUE = "ItemTopics";
	public static final int NUM_FIELDS = 8;

	public String id;
	public String year;
	public String examDate;
	public String topic;
	protected String fullSample; /* Hex string */
	public String guide;
	public String shortDesc;
	public String topicType;
	public boolean buyed;

	public ItemTopics(int index, String[] values) {
		super(index, values);

		try {
			if (values.length != NUM_FIELDS)
				throw new adbException(CLASS_UNIQUE + " length values invalid!");
		} catch (adbException e) {
			e.printStackTrace();
		}
		this.id = values[0];
		this.year = values[1];
		this.examDate = values[2];
		this.topic = values[3];
		this.fullSample = values[4];
		this.guide = values[5];
		this.shortDesc = values[6];
		this.topicType = values[7];
		this.buyed = Boolean.valueOf(values[8]);

		// F P B
		if (topicType.equals("F") || topicType.equals("B")) {
			buyed = true;
		} else {
			buyed = false;
		}
	}

	public void refreshData() {
		// F P B
		if (topicType.equals("F") || topicType.equals("B")) {
			buyed = true;
		}
	}
	
	public int getFreeResIcon(){
		if(topicType.equals("F")) return R.drawable.ic_free;
		if(topicType.equals("B")) return R.drawable.ic_sticket_bought;
		if(topicType.equals("P")) return -1;
		return -1;
	}

	public String getFullSample() {
		if (buyed)
			return HexStringConverter.getInstance()
					.hexToString(fullSample==null?"":fullSample + "");
		else
			return shortDesc==null?"":shortDesc;
	}

	@Override
	public String[] getValues() {
		values[0] = id;
		values[1] = year;
		values[2] = examDate;
		values[3] = topic;
		values[4] = fullSample;
		values[5] = guide;
		values[6] = shortDesc;
		values[7] = topicType;
		values[8] = buyed + "";
		return values;
	}
}